import axios from 'axios'
// import store from '@/store'
// import router from '@/router'
// 白名单、无需token
let sysAppId = window.g.sysAppId
const whiteList = [
  '/api/Jwt/tokensm2',
  '/api/Jwt/token',
  '/api/Jwt/RefreshAccessToken', // 更新token
  '/api/v1/mobileJwt/AccessTokenEncrypt', // 获取token
  '/api/Jwt/RefreshToken' // 令牌过期的token刷新
]
let isRefreshing = false // 控制登录过期的提示锁
let requests = [] // 缓存token刷新，需要重新发起的请求

const service = axios.create({
  baseURL: window.g.API_ROOT,
  timeout: window.g.AXIOS_TIMEOUT || 5000
})

service.interceptors.request.use(config => {
		let token = localStorage.getItem('token') || ''
    // 请求拦截
		config.headers['Authorization'] = 'Bearer ' + token
		config.headers['sysappid'] = sysAppId
		return config
  },
  error => {
    console.log(error)
    // return Promise.reject(error)
  }
)

service.interceptors.response.use(response => {
    // 响应拦截
    // console.log(response.data)
    const status = response.status
    const code = response.data ? response.data.code : 0
    // 授权失败 401，访问令牌失效 403
    if((status === 401 && code === 10050) || ((status === 401 || status === 403) && code === 10040) ) {
      // //
    }
    // 正常返回
    return response
  },
  error => {
    return Promise.resolve(error.response)
  }
)

export default service
